<template>
    <div class='auditDetails'>
        <el-dialog title="商品入库" visible @close="$emit('close')" width="1200px" append-to-body :close-on-click-modal="false">
            <el-descriptions :column="1" :size="size">
                <el-descriptions-item label="商品编号">
                    <span>{{ goods_code }}</span>
                </el-descriptions-item>
                <el-descriptions-item label="商品名称">
                    <span>{{ goods_name }}</span>
                </el-descriptions-item>
            </el-descriptions>
            <el-table border v-loading="loading" :data="tableList" ref="tableList" v-tableHeight :height="tableList &&tableList.length > 0 ? '900px' : '120px'">
                <el-table-column label="商品规格" align="center" prop="goods_spec">
                    <template slot-scope="scope">
                        <span>{{ scope.row.goods_spec.split(";;").toString().replace(/::/g, ':') }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="销售价格" align="center" prop="price_selling" />
                <el-table-column label="市场价格" align="center" prop="price_market" />
                <el-table-column label="商品库存" align="center" prop="stock_total" />
                <el-table-column label="总销统计" align="center" prop="stock_sales" />
                <el-table-column label="入库数量" align="center" prop="stock">
                    <!-- <template slot="header" slot-scope="scope">
                        <span class="mgrinr1">入库数量</span>
                        <el-button size="mini" @click="batchPrice(scope.column)">批量修改</el-button>
                    </template> -->
                    <template slot-scope="scope">
                        <el-input v-model="scope.row.stock" @change="handleChange(scope)"
                            onKeypress="return(/^[0-9]*$/.test(String.fromCharCode(event.keyCode)))"
                            @keyup.native="scope.row.stock = onInput(scope.row.stock)">
                        </el-input>
                    </template>
                </el-table-column>
            </el-table>
            <span slot="footer" class="dialog-footer">
                <el-button @click="close()">取 消</el-button>
                <el-button type="primary" @click="submit" :disabled="formLoading">确 定</el-button>
            </span>
            <!-- <pagination v-show="pageCount > 0" :pageCount="pageCount" :page.sync="queryParams.page" :limit.sync="queryParams.limit" @pagination="getList" /> -->
        </el-dialog>
    </div>
</template>
<script>
import throttle from 'lodash.throttle'
import { setHousing } from "@/api/goods/goods"
export default {
    name: 'auditDetails',
    props: {
        data: {
            type: Object,
            default: function () {
                return {}
            }
        }

    },
    components: {

    },
    data() {
        return {
            loading: false,
            formLoading: false,
            size: 'medium',
            // total: 0,
            // pageCount: 0,
            tableList: [{ stock: 0 }],
            goods_code: '',
            goods_name: '',
            items: [],

        }
    },
    created() {
        this.tableList = this.data.items;
        this.goods_code = this.data.code;
        this.goods_name = this.data.name;
        console.log(this.tableList, '商品信息')
        // let newArr = this.tableList.map(item => {
        //     return {
        //         sku: item.goods_sku,
        //         spec: item.goods_spec,
        //         stock: item.stock ? item.stock : 0
        //     }
        // })
        // console.log(newArr, 'xinshuzu')
        // this.items = JSON.stringify(newArr) 

    },
    methods: {
        close() {
            this.$emit('close');
        },
        handleChange(scope) {
            console.log(scope);
            let newArr = this.tableList.map(item => {
                return {
                    sku: item.goods_sku,
                    spec: item.goods_spec,
                    stock: item.stock ? item.stock : 0
                }
            })
            this.items = JSON.stringify(newArr)
            console.log(this.items, 'xinshuzu')
        },
        submit() {
            let params = {
                code: this.goods_code,
                items: this.items
            }
            setHousing(params).then(res => {
                this.msgSuccess("操作成功！");
                this.close()
                this.formLoading = false;
                this.getList();
            }).catch(() => {
                this.formLoading = false;
            })
        }
        // submit: throttle(function () {
        //     this.$refs.form.validate((valid) => {
        //         if (valid) {
        //             this.formLoading = true;
        //             let json = this.form
        //             json.login_pass = json.login_pass ? md5(json.login_pass) : null
        //             setUsersInfo(json).then(res => {
        //                 this.msgSuccess("操作成功！");
        //                 this.close()
        //                 this.formLoading = false;
        //                 this.getList();
        //             }).catch(() => {
        //                 this.formLoading = false;
        //             })
        //         }
        //     })
        // }, 1000, { trailing: false }),

    },
}

</script>
<style scoped lang='scss'></style>